package com.jg.tool.actable.builder.sqlite;

import cn.hutool.core.util.StrUtil;
import com.jg.tool.actable.annotation.Column;
import com.jg.tool.actable.builder.AbstractFieldBuilder;
import com.jg.tool.actable.constant.FieldType;
import com.jg.tool.actable.db.po.FieldStructure;
import com.jg.tool.actable.util.ColumnUtil;

import java.lang.reflect.Field;

/**
 * sqlite字段构建器
 * @author gaolj
 */
public abstract class AbstractSqliteFieldBuilder extends AbstractFieldBuilder {

    @Override
    public String build(Field field, Column column) {
        StringBuilder result = new StringBuilder();
        String fieldName = ColumnUtil.getTableFieldName(field, column);
        result.append(fieldName).append(" ");
        result.append(this.fieldType);
        if (!column.isNull()) {
            //判断是否不能为空
            result.append(" not null ");
        }
        if (column.isKey()) {
            //判断是否为主键
            result.append(" primary key ");
        }
        if (StrUtil.isNotEmpty(column.defaultValue())) {
            //默认值不为空
            result.append(" default '").append(column.defaultValue()).append("' ");
        }
        return result.toString();
    }

    @Override
    public String buildModify(Field field, Column column, FieldStructure fieldStructure) {
        //sqlite不支持修改
        return "";
    }
}
